#include "../../include/gui_qt_demo/funInclude/rosnode.h"
#include "../../include/gui_qt_demo/dataInclude/singleData.h"

RosNode::RosNode():
init_argc(0)
{
  char* argv_c="";
  init_argv = &argv_c;
}

RosNode::~RosNode() {
  if(ros::isStarted()) {
    ros::shutdown(); // explicitly needed since we use ros::start();
    ros::waitForShutdown();
  }
}

bool RosNode::init(){
  ros::init(init_argc,init_argv,"ide_tianbot");
  if(!ros::master::check()){
    return false;
  }
  ros::start(); // explicitly needed since our nodehandle is going out of scope.
  ros::NodeHandle n;
  DataPtr->setNodeHandle(n);
  return true;
}

bool RosNode::init(const std::string &master_url, const std::string &host_url){
  std::map<std::string,std::string> remappings;
  remappings["__master"] = master_url;
  remappings["__hostname"] = host_url;
  ros::init(remappings,"ide_tianbot");
  if(!ros::master::check()){
    return false;
  }
  ros::start(); // explicitly needed since our nodehandle is going out of scope.
  ros::NodeHandle n;
  DataPtr->setNodeHandle(n);
  return true;
}
